package ui;

import java.util.ArrayList;

import obj.Player;

import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;

import play.Things;

import util.Settings;

/**
 * Title menu.
 * @author VincentLy
 */
public class StartMenu extends BasicGameState{

	private ArrayList<CustomButton> buttons;
	private CustomButton newGame;
	private CustomButton loadGame;
	private CustomButton options;
	private CustomButton help;
	private CustomButton credits;
	private CustomButton exit;
	private float ex,ey = -1;

	public StartMenu(){
		super();
		buttons = new ArrayList<CustomButton>();
		newGame = new CustomButton(Settings.screenX/2-Settings.buttonX/2,Settings.screenY*3/4 - Settings.buttonY,"Start",'n');		
		loadGame = new CustomButton(Settings.screenX/2-Settings.buttonX/2,Settings.screenY*3/4,"Load Game",'d');		
		options = new CustomButton(Settings.screenX/2-Settings.buttonX/2,Settings.screenY*3/4 + Settings.buttonY,"Options",'o');	
		help = new CustomButton(Settings.screenX/2-Settings.buttonX/2,Settings.screenY*3/4 + 2*Settings.buttonY,"Help",'h');	
		credits = new CustomButton(Settings.screenX/2-Settings.buttonX/2,Settings.screenY*3/4 + 3*Settings.buttonY,"Credits",'c');	
		exit = new CustomButton(Settings.screenX/2-Settings.buttonX/2,Settings.screenY*3/4 + 4*Settings.buttonY,"Exit",'e');
		buttons.add(newGame);
		buttons.add(loadGame);
		buttons.add(options);
		buttons.add(help);
		buttons.add(credits);		 
		buttons.add(exit);
	}

	/**
	 * No initialization needed yet.
	 * @author VincentLy
	 */
	public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {}

	/**
	 * Holds the option menu, credit menu, data menu, and help menu.
	 * Checks for user advances.
	 * @author VincentLy
	 */
	public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
		Input i = gc.getInput();
		ex = i.getMouseX();
		ey = i.getMouseY();
		for(CustomButton b:buttons){
			if(b.contains(ex,ey)){
				b.setOn(true);	
				if(i.isMousePressed(Input.MOUSE_LEFT_BUTTON)){
					switch(b.name()){
					case 'n':	Things.player = new Player(300,300,1,Settings.player);
								sbg.enterState(Settings.gID);
								break;
					case 'd':	sbg.enterState(Settings.dID);
								break;
					case 'o':	sbg.enterState(Settings.oID);
								break;
					case 'h':	sbg.enterState(Settings.hID);
								break;
					case 'c':	sbg.enterState(Settings.cID);
								break;
					case 'e':	gc.exit();
								break;
					}
				}				
			}	
			else
				b.setOn(false);
		}	
	}

	/**
	 * Draws the components of the start menu.
	 * @author VincentLy
	 */
	public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
		g.setAntiAlias(true);
		g.setBackground(Color.black);
		g.drawImage(Settings.background,2,-140);
		g.setColor(Color.white);
		g.setLineWidth(1);
		for(CustomButton b:buttons){
			b.draw(g);	
			g.setLineWidth(1);
		}	
	}	

	/**
	 * @return id
	 * @author VincentLy
	 */
	public int getID() {return Settings.smID;}	
}